package cn.zhuangcloud.word.object.question;

public class FillQuestion implements IQuestion{

    private int blankNum;
    private String question;
    /**
     * 占位符，正则表达式形式，注意转义
     */
    private String blankPlaceholder;
    private String[] answers;
    private String[] standardAnswers;

    public FillQuestion(int blankNum, String question, String blankPlaceholder, String[] answers, String[] standardAnswers) {
        this.blankNum = blankNum;
        this.question = question;
        this.blankPlaceholder = blankPlaceholder;
        this.answers = answers;
        this.standardAnswers = standardAnswers;
    }

    public FillQuestion(String question, String blankPlaceholder, String[] answers, String[] standardAnswers) {
        this.blankNum = standardAnswers.length;
        this.question = question;
        this.blankPlaceholder = blankPlaceholder;
        this.answers = answers;
        this.standardAnswers = standardAnswers;
    }

    public int getBlankNum() {
        return blankNum;
    }

    public void setBlankNum(int blankNum) {
        this.blankNum = blankNum;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getBlankPlaceholder() {
        return blankPlaceholder;
    }

    public void setBlankPlaceholder(String blankPlaceholder) {
        this.blankPlaceholder = blankPlaceholder;
    }

    public String[] getAnswers() {
        return answers;
    }

    public void setAnswers(String[] answers) {
        this.answers = answers;
    }

    public String getType() {
        return "Fill";
    }

    public String[] getStandardAnswers() {
        return standardAnswers;
    }

    public void setStandardAnswers(String[] standardAnswers) {
        this.standardAnswers = standardAnswers;
    }

    public String getDisplay() {
        String display = question;
        for (int i = 0; i < blankNum; ++i) {
            if (answers[i].equalsIgnoreCase(standardAnswers[i])) {
                display = display.replaceFirst(blankPlaceholder, "<u>&nbsp;&nbsp;" + answers[i] + "&nbsp;&nbsp;</u><span class=\"judge\">√</span>");
            } else {
                display = display.replaceFirst(blankPlaceholder, "<u>&nbsp;&nbsp;" + answers[i] + "&nbsp;&nbsp;</u><span class=\"judge\">×&nbsp;正确答案：" + standardAnswers[i] + "</span>");
            }
        }
        return display;
    }

}
